package com.springboot.service.impl;

import com.springboot.mapper.*;
import com.springboot.model.*;
import com.springboot.service.DoctorCancelAppointService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

/**
 * 医生取消预约
 */
@Service
public class DoctorCancelAppointServiceImpl implements DoctorCancelAppointService {
    @Autowired
    private UserLoginFormMapper userLoginFormMapper;

    @Autowired
    private OrderFormMapper orderFormMapper;

    @Autowired
    private MessageInformMapper messageInformMapper;

    @Autowired
    private AssistantListFormMapper assistantListFormMapper;

    @Autowired
    private AssistantMessageInformMapper assistantMessageInformMapper;

    @Autowired
    private PatientInfoFormMapper patientInfoFormMapper;

    //通过手机号码查找用户
    @Override
    public UserLoginForm findUserByTel(String userTel)
    {
        UserLoginForm userLoginForm=userLoginFormMapper.selectByTel(userTel);
        return userLoginForm;
    }

    //通过医生id 患者id 预约日期 预约时间查找预约记录
    @Override
    public OrderForm findOrderByRecord(OrderForm orderForm)
    {
        OrderForm order=orderFormMapper.selectByForeignKey2(orderForm);
        return order;
    }

    //医生取消预约之后删除这条数据
    @Override
    public int deleteOrderMessage(Integer bookId)
    {
        return orderFormMapper.deleteByPrimaryKey(bookId);
    }

    @Override
    public int deletePatientInfo(Integer bookId)
    {
        return patientInfoFormMapper.deleteByPrimaryKey(bookId);
    }
    //将医生取消预约这个通知放到消息表中
    @Override
    public int insertIntoMessageList(MessageInform messageInform)
    {
        return messageInformMapper.insertSelective(messageInform);
    }

    //通过医生id查找负责他的助理列表
    @Override
    public ArrayList<AssistantListFormKey> findAssistantByDoctorId(Integer doctorId)
    {
        ArrayList<AssistantListFormKey> assistantListFormKeys=assistantListFormMapper.findAssistantById(doctorId);
        return assistantListFormKeys;
    }

    //把医生取消预约这条消息插入到负责它的助理信息表中
    @Override
    public int insertIntoAssistantMessageList(AssistantMessageInform assistantMessageInform)
    {
        return assistantMessageInformMapper.insertSelective(assistantMessageInform);
    }

    //通过消息记录找到这条消息
    public MessageInform findMessageByRecord(MessageInform messageInform)
    {
        return messageInformMapper.selectByRecord(messageInform);
    }
}
